From eaa872f6c303ad9a997b376eb99804f4b1af1b67 Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Tue, 14 Oct 2014 14:01:42 +0200 Subject: [PATCH] inspector: Replace reload with record and when pressed, record instance counts at 1fps. --- gtk/inspector/statistics.c | 32 +++++++++++++++++++++++++++----- gtk/inspector/statistics.ui | 8 ++++---- gtk/inspector/statistics.ui.h | 4 +++- 3 files changed, 34 insertions(+), 10 deletions(-) diff --git a/gtk/inspector/statistics.c b/gtk/inspector/statistics.c index 628c644322..69c4bc8f92 100644 --- a/gtk/inspector/statistics.c +++ b/gtk/inspector/statistics.c @@ -42,6 +42,7 @@ struct _GtkInspectorStatisticsPrivate GtkTreeViewColumn *column_cumulative2; GtkCellRenderer *renderer_cumulative2; GHashTable *counts; + guint update_source_id; }; typedef struct { @@ -113,9 +114,10 @@ add_type_count (GtkInspectorStatistics *sl, GType type) return cumulative; } -static void -update_type_counts (GtkInspectorStatistics *sl) +static gboolean +update_type_counts (gpointer data) { + GtkInspectorStatistics *sl = data; GType type; gpointer class; @@ -130,12 +132,29 @@ update_type_counts (GtkInspectorStatistics *sl) add_type_count (sl, type); } + + return TRUE; } static void -refresh_clicked (GtkWidget *button, GtkInspectorStatistics *sl) +toggle_record (GtkToggleToolButton *button, + GtkInspectorStatistics *sl) { - update_type_counts (sl); + if (gtk_toggle_tool_button_get_active (button) == (sl->priv->update_source_id != 0)) + return; + + if (gtk_toggle_tool_button_get_active (button)) + { + sl->priv->update_source_id = gdk_threads_add_timeout_seconds (1, + update_type_counts, + sl); + update_type_counts (sl); + } + else + { + g_source_remove (sl->priv->update_source_id); + sl->priv->update_source_id = 0; + } } static gboolean @@ -250,6 +269,9 @@ finalize (GObject *object) { GtkInspectorStatistics *sl = GTK_INSPECTOR_STATISTICS (object); + if (sl->priv->update_source_id) + g_source_remove (sl->priv->update_source_id); + g_hash_table_unref (sl->priv->counts); G_OBJECT_CLASS (gtk_inspector_statistics_parent_class)->finalize (object); @@ -276,7 +298,7 @@ gtk_inspector_statistics_class_init (GtkInspectorStatisticsClass *klass) gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, column_cumulative2); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, renderer_cumulative2); gtk_widget_class_bind_template_child_private (widget_class, GtkInspectorStatistics, button); - gtk_widget_class_bind_template_callback (widget_class, refresh_clicked); + gtk_widget_class_bind_template_callback (widget_class, toggle_record); } // vim: set et sw=2 ts=2: diff --git a/gtk/inspector/statistics.ui b/gtk/inspector/statistics.ui index 7c4ca20fe6..9e72d45c8f 100644 --- a/gtk/inspector/statistics.ui +++ b/gtk/inspector/statistics.ui @@ -27,11 +27,11 @@ True small-toolbar - + True - view-refresh-symbolic - Refresh - + media-record-symbolic + Collect Statistics + diff --git a/gtk/inspector/statistics.ui.h b/gtk/inspector/statistics.ui.h index b1fbb46542..c93734611d 100644 --- a/gtk/inspector/statistics.ui.h +++ b/gtk/inspector/statistics.ui.h @@ -1,4 +1,4 @@ -N_("Refresh"); +N_("Collect Statistics"); N_("Type"); N_("Self 1"); N_("Cumulative 1"); @@ -6,4 +6,6 @@ N_("Self 2"); N_("Cumulative 2"); N_("Self"); N_("Cumulative"); +N_("Self"); +N_("Cumulative"); N_("Enable statistics with GOBJECT_DEBUG=instance-count"); -- 2.30.2